package org.dllwh.utils.google.Interceptor;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName CustomInterceptor
 * @Description 自定义拦截器
 * @Date 2025-05-26 13:20
 * @版本 V 1.0.1
 * @since JDK 17
 */
@Slf4j
public class CustomInterceptor implements Interceptor {

    /**
     * 统计登录接口完成时间
     */
    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request();
        // 在请求之前添加日志
        log.info("发送请求地址：{}", request.url());
        long begin = System.currentTimeMillis();
        Response response = chain.proceed(request);
        // 在请求之后添加日志
        log.info("接口处理总用时: {} ", System.currentTimeMillis() - begin);
        return response;
    }
}
